/*
 * @file      TitereHelperTest.cpp
 * @brief     TitereHelperTest is a test file to TitereHelper functions.
 *
 * @author    Franco Riberi
 * @email     fgriberi AT gmail.com
 *
 * Contents:  Source file.
 *
 * System:    titere: Target Ideal TEmperature Rna Expression
 * Language:  C++
 *
 * @date February 3, 2015
 *
 * Copyright (C) 2015 Franco Riberi, FuDePAN
 *
 * This file is part of titere.
 *
 * titere is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * titere is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with titere. If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <biopp/biopp.h>
#include <gtest/gtest.h>

#define private public

#include "titere/Exceptions.h"
#include "titere/TitereHelper.h"

using namespace NSTitere;

TEST(NSHelperFuntionSuiteTest, checkNucleotidePassed)
{
    const biopp::NucSequence sequence("UGCAUUCUGGACAGGCGGCCU");
    bool result = NSHelperFuntion::checkNucleotide(sequence, 0u, 'U');
    EXPECT_TRUE(result);

    result = NSHelperFuntion::checkNucleotide(sequence, 6u, 'C');
    EXPECT_TRUE(result);

    result = NSHelperFuntion::checkNucleotide(sequence, sequence.length() - 1u, 'U');
    EXPECT_TRUE(result);
}

TEST(NSHelperFuntionSuiteTest, checkNucleotideFailed)
{
    const biopp::NucSequence sequence1("UGCAUUCUGGACAGGCGGCCU");
    bool result = NSHelperFuntion::checkNucleotide(sequence1, 2u, 'U');
    EXPECT_FALSE(result);

    const biopp::NucSequence sequence2("UGCAUUCUGGA");
    EXPECT_THROW(NSHelperFuntion::checkNucleotide(sequence2, sequence2.length(), 'U'), InvalidPosition);
}

TEST(NSHelperFuntionSuiteTest, countNucleotidePassed)
{
    const biopp::NucSequence sequence("UGCAUUCUGGACAGGCGGCCU");
    size_t amountOfAdenine = NSHelperFuntion::countNucleotide(0u, 12u, sequence, 'A');
    EXPECT_EQ(amountOfAdenine, 3u);

    amountOfAdenine = NSHelperFuntion::countNucleotide(4u, 16u, sequence, 'G');
    EXPECT_EQ(amountOfAdenine, 5u);

    amountOfAdenine = NSHelperFuntion::countNucleotide(0u, sequence.length() - 1, sequence, 'A');
    EXPECT_EQ(amountOfAdenine, 3u);

    const size_t amountOfUracil = NSHelperFuntion::countNucleotide(0u, sequence.length() - 1, sequence, 'U');
    EXPECT_EQ(amountOfUracil, 5u);

    const size_t amountOfGuanine = NSHelperFuntion::countNucleotide(0u, sequence.length() - 1, sequence, 'G');
    EXPECT_EQ(amountOfGuanine, 7u);

    const size_t amountOfCitocine = NSHelperFuntion::countNucleotide(0u, sequence.length() - 1, sequence, 'C');
    EXPECT_EQ(amountOfCitocine, 6u);

    EXPECT_EQ(amountOfAdenine + amountOfUracil + amountOfGuanine + amountOfCitocine, sequence.length());
}

TEST(NSHelperFuntionSuiteTest, countNucleotideFailed)
{
    const biopp::NucSequence sequence("UGCAUUCUGGACAGGCGGCCU");
    EXPECT_THROW(NSHelperFuntion::countNucleotide(0u, sequence.length(), sequence, 'A'), InvalidPosition);
}